package com.rock.code.bigdata.bigdatainterface.service;
import org.apache.log4j.Logger;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.text.SimpleDateFormat;
import java.util.Date;


/**
 * @author zhouhao
 * @description 定时建天表
 * @date 2018/9/13 11:33
 * @Version 1.0
 */
public class DayTabTimeTask implements Job {
    private static final String exec_tabname_day = "TB_KPI_VALUE_DAY_";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    Logger logger = Logger.getLogger("schedule");

    /**
     * 每天定时建表
     *
     * @param jobExecutionContext
     * @throws JobExecutionException
     */
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {

        CreateTabService createTabService = (CreateTabService) jobExecutionContext.getMergedJobDataMap().get("createTabService");
        Date today = new Date();
        String tabName = exec_tabname_day + sdf.format(today).replaceAll("-", "");
        if (createTabService.isExists(tabName)) {
            createTabService.createTabHis(tabName);
        } else {
            logger.info(tabName + "已创建");
        }
        try {
            logger.info("job start time: " + new Date());

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
